<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设备管理</title>
    <meta name="decorator" content="nblank"/>
    `
</head>
<body>
<div class="content container">
    <h2 class="page-title">设备类型管理
        <small> ${parameter.equipment.name}参数${not empty param.id?'修改':'添加'}</small>
    </h2>
    <section class="widget widget-tabs widget-table-overflow ">
        <header>
            <ul class="nav nav-tabs">
                <li><a href="${ctx}/biz/equipment/">设备类型管理</a></li>
                <li><a href="list?equipment.id=${parameter.equipment.id}">${parameter.equipment.name}参数列表</a></li>
                <li class="active"><a
                        href="javascript:;">${parameter.equipment.name}参数${not empty param.id?'修改':'添加'}</a></li>
            </ul>
        </header>
        <div class="body tab-content">
            <form:form id="inputForm" modelAttribute="parameter" action="save" method="post" class="form-horizontal">
                <form:hidden path="id"/>
                <form:hidden path="equipment.id"/>
                <form:hidden path="equipment.kid"/>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span></span>
                        参数名:</label>
                    <div class="col-sm-4">
                        <form:input path="name" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span></span>
                        标识:</label>
                    <div class="col-sm-4">
                        <form:input path="kid" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                        <label id="kidScan" class="error" style="display: none;">标识已存在，请重填</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span></span>
                        参数类型:</label>
                    <div class="col-sm-4">
                        <form:select path="type" data-width="auto" data-style="btn-primary" class="selectpicker">
                            <form:option value="string" label="字符"/>
                            <form:option value="number" label="数值"/>
                        </form:select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span></span>
                        单位:</label>
                    <div class="col-sm-4">
                        <form:select path="unit" name="unit" data-width="auto" data-style="btn-primary"
                                     class="selectpicker">
                            <form:option value="" label="请择选"/>
                            <form:options items="${fns:getDictList('biz_equip_unit')}" itemValue="value"
                                          itemLabel="label" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <div class="form-actions">
                    <div class="text-align-center">
                        <input id="btnCancel" name="btnCancel" class="btn btn-default" type="button"
                               style="margin-left: -50px;min-width:100px;" value="返 回" onClick="history.go(-1)"/>
                        <input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                               type="submit" value="保 存"/>&nbsp;
                    </div>
                </div>
            </form:form>
        </div>
    </section>
</div>
<script type="text/javascript">
    $(function () {
        $("#kid").focus(function () {
            $("#kidScan").css("display", "none");
        });
        $("#inputForm").validate({
            ignore: "",
            focusInvalid: true,
            rules: {
                "name": {required: true},
                "kid": {required: true},
                "type": {required: true},
                "unit": {required: true}
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parent());
            },
            invalidHandler: function (event, validator) {
                $("#btnSubmit").attr("disabled", false);
            },
            submitHandler: function (form) {
//                $(form).find(":submit").attr("disabled", true).attr("value", "提交中...");
                $(form).ajaxSubmit({
                    success: function (result) {
                        if (result == "success") {
                            pxTrigDlg("${ctx}/biz/equParameter?equipment.id=${parameter.equipment.id}");
                        }
                        if (result == "kidIsExist") {
                            $("#kidScan").css("display", "block");
                        }
                    }
                })
            }
        });
    });
</script>
</body>
</html>